<?php 
/* --------------------------------------------------
	Function for Wp-Undressed Themes
	Last Modified: 9/11/2006 00:36

	DON'T LOST THIS FILES
	
----------------------------------------------------- */

/* Initiate WPU Template chunking and Sidebar Widget compatibility */ 

include dirname( __FILE__ ) . '/wpudata/wpuinit.php';
include dirname( __FILE__ ) . '/wpudata/register_sidebar.php';

function wpu_option_form() {

$wpuofile = dirname( __FILE__ ) . "/wpudata/wpuconf.php"; if (file_exists($wpuofile)) { include $wpuofile; }
?>

<div class='wrap'>
<form id='wpu-option' method='post' action=''>

<table id='editform' style="width: 100%">
<tr><td colspan='2'><h2>WP-Undressed Option</h2></td></tr>
<tr><td colspan='2'><h3>Header/Top Navigation</h3></td></tr> 

<tr><th>Parent Page ID</th><td>:
	<input type='text' size='3' name='parentID' tabindex='1' value='<?php echo $taparentid ?>' /> 
	<small>Child of this page ID will shown as Header/Top Menu. 
	<i>To Disable, leave it blank</i>.</small></td></tr>

<tr><th>Page ID to exclude</th><td>:
	<input type='text' size='15' name='excludeid' tabindex='2' value='<?php echo $taexclude ?>' /> 
	<small>Comma separated list of Page numeric IDs to be excluded.</small></td></tr>

<tr><th>Depth Level</th><td>:
	<input type='text' size='3' name='navdepth' tabindex='3' value='<?php echo $tanavdepth ?>' /> 
	<small>Defaults to 0 (display all pages).</small></td></tr>

<tr><td colspan='2'><h3>Categories</h3></td></tr> 

<tr><th>Category ID to be hidden</th><td>:
	<input type='text' size='15' name='cathide' tabindex='4' value='<?php echo $tacathide ?>' /> 
	<small>Sets the categories to be excluded from the list. (ex: 1, 2, 3) in <a href='http://wp.local/wp-admin/themes.php?page=wpu-chunk_plugins.php&amp;chunk=side-cat.php'>side-cat.php</a></small></td></tr>

<tr><td colspan='2'><h3>Other options</h3></td></tr> 

<tr><th>Time Format</th><td>:<?php if ($tatimefmt == "") { $tatimefmt = "F j, Y"; } ?>
	<input type='text' size='32' name='tatimefmt' tabindex='5' value='<?php echo $tatimefmt ?>' /> 
	<small>codex: <a href="http://codex.wordpress.org/Formatting_Date_and_Time">Formatting Date and Time</a></small></td></tr>

	<tr><th>Sub Header</th><td>:
	<input type='text' size='1' name='dosubhead' tabindex='5' value='<?php echo $tadosubhead ?>' /> 
	<small>1 to enable. (Edit: <a href='http://wp.local/wp-admin/themes.php?page=wpu-chunk_plugins.php&amp;chunk=sub-header.php'>sub-header.php</a>)</small></td></tr>

<tr><th>Sub Footer</th><td>:
	<input type='text' size='1' name='dosubfoot' tabindex='6' value='<?php echo $tadosubfoot ?>' /> 
	<small>1 to enable. (Edit: <a href='http://wp.local/wp-admin/themes.php?page=wpu-chunk_plugins.php&amp;chunk=sub-footer.php'>sub-footer.php</a>)</small></td></tr>

<?php if ( function_exists('register_sidebar') ) { ?>

	<tr><td colspan='2'><h2>Sidebar Widget</h2></td></tr>
	<?php if (!$tasdwidget) { $tasdwidget = "Sidebar1, Sidebar2"; } ?>

	
	<tr><th>Sidebar Register</th><td>:
	<input type='text' size='45' name='sdwidget' tabindex='7' value='<?php echo $tasdwidget ?>' 
	onchange="
 		var tare = /[^A-Za-z0-9_,]|(,$)/g; var taov = this.value; var tanv=this.value.replace(tare,''); this.value=tanv;
	"
	/>
	<small>Name your sidebar widget. (ex: Home, Blog, Archive)</small></td></tr>

	<tr><th>Use Condition placement?</th><td>:
		<input type='text' size='3' name='taautoplace' tabindex='10' value='<?php echo $taautoplace ?>' />
		<small>1 to enable. To Disable, leave it blank. (See Codex: <a href='http://codex.wordpress.org/Conditional_Tags'>Conditional Tags</a>)</small></td></tr>

	<?php foreach((explode(',',$tasdwidget)) as $sdw){
		$sidebar_condition = ${ltrim($sdw)."_condition"};
		echo "<tr><th><small>".$sdw."</small></th><td><span>: </span>";
		
		$n = 0; 
		while($n <= 4) { echo wpu_condpol($sdw,$sidebar_condition[$n],$n); $n++; }
		
		echo"</td></tr>";
	} 


}?>

</table>

<p class='submit'>
<input type='submit' name='wpu_submit' value='Save' tabindex='8' /></p>
</form>
</div>

<?php }

function wpu_condpol($sidebar,$condition,$nnn) {
	$cond_selection  = "<select name='".$sidebar."_condition[".$nnn."]' id='".trim($sidebar).$nnn."-condition-select'>\n";
	$WP2CONDITION = ",is_home,is_single,is_page,is_category,is_author,is_date,is_year,is_month,is_day,is_time,is_archive,is_search,is_404,is_paged,is_feed,is_trackback";

	foreach((explode(',',$WP2CONDITION)) as $WP2COND) { 
		if (trim($WP2COND) == trim($condition)) { $sel = ' selected="selected"'; }
		if ($WP2COND=="") { $wpcop= "&nbsp;"; } else { $wpcop = $WP2COND; }
		$cond_selection  .= "\t<option value='".trim($WP2COND)."'".$sel.">".$wpcop."</option>\n";
		$sel ="";
	}
	$cond_selection .="</select>\n";
	return $cond_selection;
}

function wpu_option_page() {

	if ($_REQUEST['wpu_submit']=="Save") { 
		$str_to_save ="<?php\n global \$tatimefmt;\n global \$taparentid;\n global \$tadosubhead;\n global \$tadosubfoot;\n global \$tacathide;".
		"\n \$taparentid='".$_REQUEST['parentID']
		."';\n \$taexclude='".$_REQUEST['excludeid']
		."';\n \$tanavdepth='".$_REQUEST['navdepth']
		."';\n \$tadosubhead='".$_REQUEST['dosubhead']
		."';\n \$tadosubfoot='".$_REQUEST['dosubfoot']
		."';\n \$tacathide='".$_REQUEST['cathide']
		."';\n \$taautoplace='".$_REQUEST['taautoplace']
		."';\n \$tatimefmt='".$_REQUEST['tatimefmt']
		."';\n \$tasdwidget='".$_REQUEST['sdwidget']."';\n";
		foreach((explode(',',$_REQUEST['sdwidget'])) as $sdw) { 
			$sdw=ltrim($sdw);
			$str_to_save .= " \$".$sdw."_condition=array(";
			if($_REQUEST[$sdw.'_condition']) {
				foreach($_REQUEST[$sdw.'_condition'] as $thecondition) { $str_to_save .= "'$thecondition',"; }
			}
			$str_to_save .= ");\n";
		}

		$str_to_save .= "\n?>";		


		$tafp = fopen(dirname( __FILE__ ) . '/wpudata/wpuconf.php',"w");
		fputs($tafp,$str_to_save,strlen($str_to_save));
		fclose($tafp);
				
		wpu_option_form();


	} else {
		wpu_option_form();
	}

}

function wpuo_register() {
	add_theme_page('WP-Undressed Options', 'WPU Options', 'edit_themes', basename(__FILE__), 'wpu_option_page');
}

add_action('admin_menu', 'wpuo_register');

?>